package concurrent;

/**
 * a获得了锁
 * b获得了锁 (5S之后)
 * a wait之后
 *
 * 结论:main wait(time)之后线程醒来.但是并没有获得锁
 *
 */
public class WaitTest1 {
    public static void main(String[] args) throws InterruptedException {
        WaitTest1 a = new WaitTest1();
        Runnable b = () -> {
            synchronized (a) {
                System.out.println("b获得了锁");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        synchronized (a) {
            System.out.println("a获得了锁");
            new Thread(b).start();
            a.wait(500);
            System.out.println("a wait之后");
        }
    }
}
